home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
-
- # debugging output
- # set -x
-
- # NOTES:
- # depends on Habaerli tools and either ghostscript or psrip
-
- # global variables used in the script
- progname="showtogif"
- usage="Usage: $progname infile outfile"
-
- execdir="/usr/lib/CosmoCreate/apps/"
-
- showcase=/usr/sbin/showcase
- psrip=/usr/lib/print/psrip
- psprolog=/usr/lib/print/data/PSRIPprolog
- gs1=/usr/bin/X11/gs
- gs2=/usr/freeware/bin/gs
-
- tmpdir="/tmp/"
- fileprefix=".s2g"
- prefix="$tmpdir$fileprefix"
-
- starterr="xconfirm -header showtogif -t Error:"
- enderr="-icon error -B Ok"
-
- infile=$1
- outfile=$2
-
- # make up a unique name (unique enough)
- tmpfile=`date +%j%H%M%S`$$
-
- # make sure there are exactly 2 arguments
- if [ $# -ne 2 ]; then
- $starterr -t "Wrong number of arguments." \
- -t "$usage" \
- $enderr
- exit 1
- fi
-
- # make sure input file is readable
- if [ ! -r $infile ]; then
- $starterr -t "Input file unreadable." \
- $enderr
- exit 1
- fi
-
- # make sure output file is writable
- touch $outfile
- if [ ! -w $outfile ]; then
- $starterr -t "Output file unwritable." \
- $enderr
- exit 1
- fi
-
- # make sure showcase exists
- if [ ! -x $showcase ]; then
- $starterr -t "Showcase not found." \
- $enderr
- exit 1
- fi
-
- # make sure gs or psrip exists
- if [ -x $psrip -a -r $psprolog ]; then
- psrip=1
- else
- if [ -x $gs1 ]; then
- psrip=0
- gs=$gs1
- elif [ -x $gs2 ]; then
- psrip=0
- gs=$gs2
- else
- $starterr -t "Didn't find Ghostscript" \
- -t "or Impressario psrip." \
- -t "One of these must be" \
- -t "installed to convert from" \
- -t "Showcase to GIF." \
- $enderr
- exit 1
- fi
- fi
-
- # convert from showcase to postscript
- showcase -p $infile > $prefix.$tmpfile.ps
-
- # convert from postscript to encapsulated postscript
- ${execdir}pstoeps $prefix.$tmpfile.ps $prefix.$tmpfile
-
- # stop showcase from scaling and rotating the page, and fix bbox
- ${execdir}fixshow $prefix.$tmpfile.ps $prefix.${tmpfile}0001.eps $prefix.${tmpfile}.eps
-
- # convert from encapsulated postscript to rgba
- if [ $psrip -eq 1 ]; then
- ${execdir}fromeps $prefix.${tmpfile}.eps $prefix.$tmpfile.rgba -a
- else
- ${execdir}epstorgba $prefix.${tmpfile}.eps $prefix.$tmpfile.rgba $gs -a
- fi
-
- # convert from rgba to rgb
- ${execdir}trans128 $prefix.$tmpfile.rgba $prefix.$tmpfile.rgb
-
- # crop the transparent region as small as possible
- ${execdir}cropimg128 $prefix.$tmpfile.rgb $prefix.$tmpfile.crop.rgb
-
- # convert from rgb to gif
- ${execdir}togif $prefix.$tmpfile.crop.rgb $outfile -n 256 -x 128 128 128
-
- # clean up tmp directory
- rm $prefix.${tmpfile}*
-
- exit 0
-
-